#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->btn_start->setEnabled(true);
    ui->btn_stop->setEnabled(false);

    connect(&timer,SIGNAL(timeout()), this, SLOT(on_mytimeout()));

    ui->lineEdit_elapsedTime->setEnabled(false);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_btn_start_clicked()
{
    ui->btn_start->setEnabled(false);
    ui->btn_stop->setEnabled(true);
    ui->spinBox_timeCycle->setEnabled(false);

    on_mytimeout();

    timer.start(ui->spinBox_timeCycle->value());
    elapsedTimer.start();

}

void Widget::on_btn_stop_clicked()
{
    ui->btn_start->setEnabled(true);
    ui->btn_stop->setEnabled(false);
    ui->spinBox_timeCycle->setEnabled(true);

    timer.stop();
    int mymsec = elapsedTimer.elapsed();
    int mysec = mymsec/1000;
    mymsec %= 1000;

    ui->lineEdit_elapsedTime->setText(QString("已流逝%1秒-%2毫秒").arg(mysec).arg(mymsec));
}

void Widget::on_mytimeout()
{
    QTime time = QTime::currentTime();

    ui->lcd_hour->display(time.hour());
    ui->lcd_min->display(time.minute());
    ui->lcd_sec->display(time.second());
}

